package com.yz.food.controller;

import com.yz.food.pojo.Category;
import com.yz.food.pojo.Food;
import com.yz.food.pojo.Recipes;
import com.yz.food.service.CategoryService;
import com.yz.food.service.FoodService;
import com.yz.food.service.RecipesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class PageController {
    @Autowired
    private RecipesService recipesService;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private FoodService foodService;

    @RequestMapping("page/index")
    public String pageIndex(ModelMap modelMap) {
        // 获取页面食谱
        List<Recipes> recipes = recipesService.getRandom();
        modelMap.addAttribute("recipes", recipes);
        // 获取分类
        List<Category> categories = categoryService.getAll();
        modelMap.addAttribute("categories", categories);
        List<Food> foods = foodService.getByHot();
        modelMap.addAttribute("foods", foods);
        return "index";
    }

    @RequestMapping("page/notFound")
    public String pageNotFound() {
        return "404";
    }




}
